import { _decorator, Color, Component, Node, PolygonCollider2D, RigidBody2D, Sprite, UITransform } from 'cc';
import { HoleAction } from './HoleAction';
const { ccclass, property } = _decorator;

@ccclass('ElementAction')
export class ElementAction extends Component {
    layerColor: Color;
    
    start() {

    }

    update(deltaTime: number) {
        
    }

    initColor(layerColor: Color){
        this.layerColor = layerColor;
        let img = this.node.getChildByName("img")?.getComponent(Sprite);
        if(img) {
            img.color = layerColor;
        }
    }

    initPin(groupId: number) {

        console.log('矛头分组', groupId, this.node.getComponent(RigidBody2D).group)
        
        this.node.getComponent(RigidBody2D).group = groupId;
        this.node.getComponent(PolygonCollider2D).group = groupId;

        this.node.children.forEach((child) => {
            //element,image,hole
            if (child.getComponent(HoleAction)) {
                child.getComponent(HoleAction).initPin(2);
            }
        })
    }
}


